#!/bin/bash

echo "===================================="
echo "金融监控系统后端服务启动"
echo "===================================="
echo ""

echo "检查Python环境..."
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3，请先安装Python 3.8+"
    exit 1
fi

python3 --version
echo ""

echo "检查依赖包..."
if ! python3 -c "import fastapi" &> /dev/null; then
    echo "正在安装依赖包..."
    pip3 install -r requirements.txt
fi

echo ""
echo "后台启动服务器..."
echo "服务地址: http://localhost:10001"
echo "API文档: http://localhost:10001/docs"
echo ""

# 创建日志目录
mkdir -p logs

# 后台运行服务并将日志输出到文件
nohup python3 main.py > logs/backend.log 2>&1 &
echo "服务已在后台启动，PID: $!"
echo "日志文件位置: logs/backend.log"
